﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CostaRicaPureTravelUtils.PRResourcesUtils;

namespace CostaRicaPureTravel.UserControls
{
    public partial class AjaxBasedPopUpControl : System.Web.UI.UserControl
    {
        public String TargetID
        {
            set { mpeMessagePopup.TargetControlID = TargetID; }
            get { return mpeMessagePopup.TargetControlID; }
        }

        String message;
        public String Message
        {
            set { message = PRResources.GetString(value); }
            get { return message; }
        }

        public PopupMessageType MessageType
        {
            set;
            get;
        }

        protected void Page_Init(object sender, EventArgs e)
        {            
            Page.Header.Controls.Add(new LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/PopUpStyle.css") + "\" />"));
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        
        }

        protected void OnEvent(object sender, EventArgs e)
        {
             
        }

        public EventHandler EventDelegate 
        {
            set { btnOkButton.Click += new System.EventHandler(value);  }
        }

        /// <summary>
        /// Details: Change modal popup image according to PopupMessageType
        /// </summary>
        /// <param name="message"></param>
        /// <param name="messageType"></param>
        public void ShowPopupMessage()
        {
            switch (MessageType)
            {
                case PopupMessageType.Error:
                    lblMessagePopupHeading.Text = Resources.Resource.CONTROL_MESSAGE_TYPE_ERROR;
                    //Render image in literal control
                    ltrMessagePopupImage.Text = "<img src='" +
                      Page.ResolveUrl("~/images/error.png") + "' alt='' />";
                    break;
                case PopupMessageType.Message:
                    lblMessagePopupHeading.Text = Resources.Resource.CONTROL_MESSAGE_TYPE_MESSAGE;
                    ltrMessagePopupImage.Text = "<img src='" +
                      Page.ResolveUrl("~/images/imgInformation.png") + "' alt='' />";
                    break;
                case PopupMessageType.Warning:
                    lblMessagePopupHeading.Text = Resources.Resource.CONTROL_MESSAGE_TYPE_WARNING;
                    ltrMessagePopupImage.Text = "<img src='" +
                      Page.ResolveUrl("~/images/warning.png") + "' alt='' />";
                    break;
                case PopupMessageType.Success:
                    lblMessagePopupHeading.Text = Resources.Resource.CONTROL_MESSAGE_TYPE_SUCCESS;
                    ltrMessagePopupImage.Text = "<img src='" +
                      Page.ResolveUrl("~/images/ok.png") + "' alt='' />";
                    break;
                default:
                    lblMessagePopupHeading.Text = Resources.Resource.CONTROL_MESSAGE_TYPE_MESSAGE;
                    ltrMessagePopupImage.Text = "<img src='" +
                      Page.ResolveUrl("~/images/imgInformation.png") + "' alt='' />";
                    break;
            }

            lblMessagePopupText.Text = Message;
            mpeMessagePopup.Show();
        }

        /// <summary>
        /// Message type enum
        /// </summary>
        public enum PopupMessageType
        {
            Error,
            Message,
            Warning,
            Success
        }
    }
}